#!/usr/bin/python
# -*- coding: UTF-8 -*-
'''
#对值进行排序
list=sorted(dict.items(),key=lambda item:item[1],reverse=True)
list=[item for item in list if item[1]>10]
'''

class datafilter(object):
    def __init__(self,data):
        self.data=data
        self.types=self.get_product_type()

    def get_word_freq(self,titles):
        dict_word={}
        for title in titles:
            for word in title.split(" "):
                if word not in dict_word:
                    dict_word[word]=1
                else:
                    dict_word[word]+=1
        return dict_word

    def get_product_type(self):
        f = open("resultType.txt", "r", encoding="utf-8")
        list = [i.strip() for i in f.readlines()]
        f.close()
        return list

    def filter_price(self,price):
        if price ==" ":
            return 0
        else:
            result=float(price.split(" ")[1])
            return result

    def filter_title(self,title):
        result="未知"
        for type in self.types:
            if type in title:
                result=type
        return result

    def get_filter_result(self):
        self.data["title"]=self.data["title"].apply(self.filter_title)
        self.data["price"]=self.data["price"].apply(self.filter_price)
        self.data["deal"]=self.data["deal"].astype(float)
        return self.data









